package cn.yunhe.server;

import cn.yunhe.dao.ITestDao;
import cn.yunhe.entity.Test;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestServer {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession();
    ITestDao testDao = session.getMapper(ITestDao.class);

    /**
     * 插入试卷答案
     * @param testName
     * @param pId
     * @return
     */
    public boolean InsertTest(String testName,int pId){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("testName",testName);
        map.put("pId",pId);
        boolean flag = testDao.InsertTest(map);
        if (flag){
            session.commit();
            return true;
        }else {
            return false;
        }
    }

    /**
     * 插入试卷名称
     * @param testName
     * @return
     */
    public boolean InsertTestName(String testName){
        boolean flag = testDao.InsertTestName(testName);
        if (flag){
            session.commit();
            return true;
        }else {
            return false;
        }
    }

    /**
     * 查询试卷ID
     * @param testName
     * @return
     */
    public Test SelectTestId(String testName){
        return testDao.SelectTestId(testName);
    }

    /**
     * 查询所有试题
     * @return
     */
    public List<Test> SelectAllTest(){
        return testDao.SelectAllTest();
    }

}
